home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / Ghostscript / src / gxdevmem.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-01  |  10.4 KB  |  244 lines

  1. /* Copyright (C) 1989, 1995, 1997, 1998, 1999 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of AFPL Ghostscript.
  4.   
  5.   AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  6.   distributor accepts any responsibility for the consequences of using it, or
  7.   for whether it serves any particular purpose or works at all, unless he or
  8.   she says so in writing.  Refer to the Aladdin Free Public License (the
  9.   "License") for full details.
  10.   
  11.   Every copy of AFPL Ghostscript must include a copy of the License, normally
  12.   in a plain ASCII text file named PUBLIC.  The License grants you the right
  13.   to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14.   conditions described in the License.  Among other things, the License
  15.   requires that the copyright notice and this notice be preserved on all
  16.   copies.
  17. */
  18.  
  19. /*$Id: gxdevmem.h,v 1.2 2000/09/19 19:00:36 lpd Exp $ */
  20. /* Structure and procedures for memory devices */
  21. /* Requires gxdevice.h */
  22.  
  23. #ifndef gxdevmem_INCLUDED
  24. #  define gxdevmem_INCLUDED
  25.  
  26. #include "gxrplane.h"
  27.  
  28. /*
  29.  * A 'memory' device is essentially a stored bitmap.
  30.  * There are several different kinds: 1-bit black and white,
  31.  * 2-, 4-, and 8-bit mapped color, 16- and 24-bit RGB color,
  32.  * and 32-bit CMYK color.  (16-bit uses 5/6/5 bits per color.)
  33.  * All use the same structure, since it's so awkward to get the effect of
  34.  * subclasses in C.
  35.  *
  36.  * Memory devices come in two flavors: standard, which always stores bytes
  37.  * big-endian, and word-oriented, which stores bytes in the machine order
  38.  * within 32-bit "words".  The source data for copy_mono and
  39.  * copy_color must be in big-endian order, and since memory devices
  40.  * also are guaranteed to allocate the bitmap consecutively,
  41.  * the bitmap of a standard memory device can serve directly as input
  42.  * to copy_mono or copy_color operations.  This is not true of word-oriented
  43.  * memory devices, which are provided only in response to a request by
  44.  * a customer with their own image processing library that uses this format.
  45.  *
  46.  * In addition to the device structure itself, memory devices require two
  47.  * other pieces of storage: the bitmap, and a table of pointers to the scan
  48.  * lines of the bitmap.  Clients have several options for allocating these:
  49.  *
  50.  *    1) Set bitmap_memory to an allocator before opening the device.
  51.  *    With this option, opening the device allocates the bitmap and the
  52.  *    line pointer table (contiguously), and closing the device frees
  53.  *    them.
  54.  *
  55.  *    2) Set line_pointer_memory to an allocator, base to the base address
  56.  *    of the bitmap, and raster to the length of each scan line (distance
  57.  *    from one scan line to the next) before opening the device.  With
  58.  *    this option, opening the device allocates the line table, but not
  59.  *    the bitmap; closing the device frees the table.
  60.  *
  61.  *    3) Set line_pointer_memory but not base or raster.  Opening /
  62.  *    closing the device will allocate / free the line pointer table, but
  63.  *    the client must set the pointers with a subsequent call of
  64.  *    gdev_mem_set_line_ptrs.
  65.  *
  66.  *    4) Set neither _memory field.  In this case, it's up to the client
  67.  *    to call gdev_mem_set_line_ptrs and to manage storage for the
  68.  *    line pointers and the bitmap.
  69.  *
  70.  * In cases (2) through (4), it is the client's responsibility to set
  71.  * foreign_bits (and foreign_line_pointers, if the line pointers are not
  72.  * contiguous with the bits) to tell the GC whether to trace the pointers.
  73.  * By default, anything allocated by bitmap_memory or line_pointer_memory is
  74.  * assumed GC'able (i.e., case (1) assumes that the bits + line pointers are
  75.  * GC'able, and cases (2) and (3) assume that the line pointers are GC'able,
  76.  * but not the bits), but the client can change the foreign_* flag(s) after
  77.  * opening the device if this is not the case.
  78.  */
  79. #ifndef gx_device_memory_DEFINED
  80. #  define gx_device_memory_DEFINED
  81. typedef struct gx_device_memory_s gx_device_memory;
  82. #endif
  83.  
  84. struct gx_device_memory_s {
  85.     gx_device_forward_common;    /* (see gxdevice.h) */
  86.     /*
  87.      * The following may be set by the client before or just after
  88.      * opening the device.  See above.
  89.      */
  90.     uint raster;        /* bytes per scan line */
  91.     byte *base;
  92. #define scan_line_base(dev,y) ((dev)->line_ptrs[y])
  93.     gs_memory_t *bitmap_memory;    /* allocator for bits + line pointers */
  94.     bool foreign_bits;        /* if true, bits are not in GC-able space */
  95.     gs_memory_t *line_pointer_memory;  /* allocate for line pointers */
  96.     bool foreign_line_pointers;  /* if true, line_ptrs are not in GC-able space */
  97.     /*
  98.      * The following are only used for planar devices.  num_planes == 0
  99.      * means this is a chunky device.  Note that for planar devices, we
  100.      * require color_info.depth = the sum of the individual plane depths.
  101.      */
  102.     int num_planes;
  103.     gx_render_plane_t planes[GX_DEVICE_COLOR_MAX_COMPONENTS];
  104.     /*
  105.      * End of client-initializable fields.
  106.      */
  107.     gs_matrix initial_matrix;    /* the initial transformation */
  108.     byte **line_ptrs;        /* scan line pointers */
  109.     /* Following is used for mapped color, */
  110.     /* including 1-bit devices (to specify polarity). */
  111.     gs_const_string palette;    /* RGB triples */
  112.     /* Following is only used for 24-bit color. */
  113.     struct _c24 {
  114.     gx_color_index rgb;    /* cache key */
  115.     bits32 rgbr, gbrg, brgb;    /* cache value */
  116.     } color24;
  117.     /* Following are only used for alpha buffers. */
  118.     /* The client initializes those marked with $; */
  119.     /* they don't change after initialization. */
  120.     gs_log2_scale_point log2_scale;    /* $ oversampling scale factors */
  121.     int log2_alpha_bits;    /* $ log2 of # of alpha bits being produced */
  122.     int mapped_x;        /* $ X value mapped to buffer X=0 */
  123.     int mapped_y;        /* lowest Y value mapped to buffer */
  124.     int mapped_height;        /* # of Y values mapped to buffer */
  125.     int mapped_start;        /* local Y value corresponding to mapped_y */
  126.     gx_color_index save_color;    /* last (only) color displayed */
  127.     /* Following are used only for planar devices. */
  128.     int plane_depth;        /* if non-zero, depth of all planes */
  129. };
  130.  
  131. extern_st(st_device_memory);
  132. #define public_st_device_memory() /* in gdevmem.c */\
  133.   gs_public_st_composite_use_final(st_device_memory, gx_device_memory,\
  134.     "gx_device_memory", device_memory_enum_ptrs, device_memory_reloc_ptrs,\
  135.     gx_device_finalize)
  136. #define st_device_memory_max_ptrs (st_device_forward_max_ptrs + 2)
  137. #define mem_device_init_private\
  138.     0,            /* raster */\
  139.     (byte *)0,        /* base */\
  140.     0,            /* bitmap_memory */\
  141.     true,            /* foreign_bits (default) */\
  142.     0,            /* line_pointer_memory */\
  143.     true,            /* foreign_line_pointers (default) */\
  144.     0,            /* num_planes (default) */\
  145.     { { 0 } },        /* planes (only used for planar) */\
  146.     { identity_matrix_body },    /* initial matrix (filled in) */\
  147.     (byte **)0,        /* line_ptrs (filled in by mem_open) */\
  148.     { (byte *)0, 0 },    /* palette (filled in for color) */\
  149.     { gx_no_color_index },    /* color24 */\
  150.     { 0, 0 }, 0,        /* scale, log2_alpha_bits */\
  151.     0, 0, 0, 0,        /* mapped_* */\
  152.     gx_no_color_index    /* save_color */
  153.  
  154. /*
  155.  * Memory devices may have special setup requirements.  In particular, it
  156.  * may not be obvious how much space to allocate for the bitmap.  Here is
  157.  * the routine that computes this from the width and height.  Note that this
  158.  * size includes both the bitmap and the line pointers.
  159.  */
  160. /* bits only */
  161. ulong gdev_mem_bits_size(P3(const gx_device_memory *mdev, int width,
  162.                 int height));
  163. /* line pointers only */
  164. ulong gdev_mem_line_ptrs_size(P3(const gx_device_memory *mdev, int width,
  165.                  int height));
  166. /* bits + line pointers */
  167. ulong gdev_mem_data_size(P3(const gx_device_memory *mdev, int width,
  168.                 int height));
  169.  
  170. #define gdev_mem_bitmap_size(mdev)\
  171.   gdev_mem_data_size(mdev, (mdev)->width, (mdev)->height)
  172.  
  173. /*
  174.  * Do the inverse computation: given the device width and a buffer size,
  175.  * compute the maximum height.
  176.  */
  177. int gdev_mem_max_height(P3(const gx_device_memory *, int, ulong));
  178.  
  179. /*
  180.  * Compute the standard raster (data bytes per line) similarly.
  181.  */
  182. #define gdev_mem_raster(mdev)\
  183.   gx_device_raster((const gx_device *)(mdev), true)
  184.  
  185. /* Determine the appropriate memory device for a given */
  186. /* number of bits per pixel (0 if none suitable). */
  187. const gx_device_memory *gdev_mem_device_for_bits(P1(int));
  188.  
  189. /* Determine the word-oriented memory device for a given depth. */
  190. const gx_device_memory *gdev_mem_word_device_for_bits(P1(int));
  191.  
  192. /* Make a memory device. */
  193. /* mem is 0 if the device is temporary and local, */
  194. /* or the allocator that was used to allocate it if it is a real object. */
  195. /* page_device is 1 if the device should be a page device, */
  196. /* 0 if it should propagate this property from its target, or */
  197. /* -1 if it should not be a page device. */
  198. void gs_make_mem_mono_device(P3(gx_device_memory * mdev, gs_memory_t * mem,
  199.                 gx_device * target));
  200. void gs_make_mem_device(P5(gx_device_memory * mdev,
  201.                const gx_device_memory * mdproto,
  202.                gs_memory_t * mem, int page_device,
  203.                gx_device * target));
  204. void gs_make_mem_abuf_device(P6(gx_device_memory * adev, gs_memory_t * mem,
  205.                 gx_device * target,
  206.                 const gs_log2_scale_point * pscale,
  207.                 int alpha_bits, int mapped_x));
  208. void gs_make_mem_alpha_device(P4(gx_device_memory * adev, gs_memory_t * mem,
  209.                  gx_device * target, int alpha_bits));
  210.  
  211. /*
  212.  * Open a memory device, only setting line pointers to a subset of its
  213.  * scan lines.  Banding devices use this (see gxclread.c).
  214.  */
  215. int gdev_mem_open_scan_lines(P2(gx_device_memory *mdev, int setup_height));
  216.  
  217. /*
  218.  * Initialize the line pointers of a memory device.  base and/or line_ptrs
  219.  * may be NULL, in which case the value already stored in the device is
  220.  * used; if base is NULL, raster is also ignored and the existing value is
  221.  * used.  Note that this takes raster and setup_height arguments.
  222.  * If the base is not NULL and the device is planar, all planes must have
  223.  * the same depth, since otherwise a single raster value is not sufficient.
  224.  *
  225.  * Note that setup_height may be less than height.  In this case, for
  226.  * planar devices, only setup_height * num_planes line pointers are set,
  227.  * in the expectation that the device's height will be reset to
  228.  * setup_height.
  229.  */
  230. int gdev_mem_set_line_ptrs(P5(gx_device_memory *mdev,
  231.                   byte *base, int raster, byte **line_ptrs,
  232.                   int setup_height));
  233.  
  234. /* Define whether a monobit memory device is inverted (black=1). */
  235. void gdev_mem_mono_set_inverted(P2(gx_device_memory * mdev, bool black_is_1));
  236.  
  237. /* Test whether a device is a memory device. */
  238. bool gs_device_is_memory(P1(const gx_device *));
  239.  
  240. /* Test whether a device is an alpha-buffering device. */
  241. bool gs_device_is_abuf(P1(const gx_device *));
  242.  
  243. #endif /* gxdevmem_INCLUDED */
  244.